import { Init, Inject, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { Equal, Repository } from 'typeorm';
import { UserAddressEntity } from '../entity/address';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { UserAudioSettingEntity } from '../entity/setting';

/**
 * 背景音乐设置
 */
@Provide()
export class UserSettingService extends BaseService {
  @InjectEntityModel(UserAudioSettingEntity)
  UserAudioSettingEntity: Repository<UserAudioSettingEntity>;

  @Inject()
  ctx;

  async settingUserInfo(){
    return await UserAudioSettingEntity.findOneBy({userId:this.ctx.user.id})
  }

  async add(param){
    let info=await UserAudioSettingEntity.findOneBy({userId:param.userId})
    if(info){
      return await UserAudioSettingEntity.save({id:info.id,...param})
    }else{
      return await UserAudioSettingEntity.insert(param)
    }
  }
}
